
import DataAccess.DataAccess;
import domain.AcademicSet;
import domain.AccUser;
import domain.Author;
import domain.Car;
import domain.Element;
import domain.Format;
import domain.Publisher;
import domain.Reference;
import domain.Translator;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.faces.application.FacesMessage;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.component.UIData;
import javax.faces.context.FacesContext;
import org.primefaces.event.DragDropEvent;
import serverTier.AccessInterfaceLocal;

@ManagedBean(name = "user")
@SessionScoped
public class UserBean {

    @EJB
    private AccessInterfaceLocal Userservice;
    /*private String email = "";
    private String password; */
    private String email = "gavin@cross.com";
    private String password = "g"; 
    private String currentpassword; 
    private AccUser current;
    private Date currentDataAndDate;
    private boolean login = false;
    private boolean login2 = true;
    //private List<AccUser> allusers = Userservice.getAllUser();
    private String title;
    private String rYear;
    private String edition;
    //private String publisher;
    private String city;
    private String doi;
    private String isbn10;
    private String isbn13;
    private String eisbn13;
    private Set<String> authors;
    private Set<String> translators;
    private String type;
    private String pages;
    private String volume;
    private String issue;
    private String address;
    private String date;
    private Date date2;
    private String other;
    private String language;
    private Map<String, String> languages = new HashMap<String, String>();
    private String subject;
    private String txt1;
    private String aname;
    private String asname;
    /*private char in1 = '-';
     private char in2 = '-';
     private char in3 = '-';
     private char in4 = '-';
     private char in5 = '-';*/
    private String aname1 = " ";
    private String aname2 = " ";
    private String aname3 = " ";
    private String aname4 = " ";
    private String aname5 = " ";
    private String pname;
    private String pcountry;
    private int number1 = 0;
    //private Set<Author> authorslist = new HashSet<Author>();
    //private Set<Author> translatorlist = new HashSet<Author>();
    private String name;
    //private String email;
    //private String password; 
    private String error;
    private UIData dataTable; //authoer
    private UIData dataTable2; //ref
    private UIData dataTable3; //noyetused
    private UIData dataTable4; //noyetused
    private UIData dataTable5;
    private UIData dataTable6;
    private UIData dataTableForViewSets;
    private Author selectedAuthor;
    private Reference selectedReference;
    private Translator selectedTranslator;
    private int numberAuthor = 0;
    //private int countAuthorlistSize = 0;
    //private int countTranslatorlistSize = 0;
    private String SelectedReferencePub;
    private String SelectedReferencePubcountry;
    private int oldPubID; //if -111 ceate else edit PUB addEditPub()
    private AcademicSet selectedAcademicSet;
    private String selectedAcademicSetName;
    private String selectedAcademicSetNameForRename;
    private Reference selectedSetReference;
    private Reference selectedReferenceFromAll;
    private Format selectedFormat;
    private Format currentFormat = new Format();
    private String selectedFormatNameForRename;
    private String sample;
    private boolean hasPub = false;
    private boolean renderEdition, renderCity, renderDoi, renderIsbn,
            renderPages, renderVolume, renderIssue, renderUrl, renderDate = false;
    private boolean renderOnRowSelect = false;
    private boolean renderOnRowSelectREF = false;
    private boolean renderOnRowSelectSET = false;
    private boolean renderOnRowSelectFOR = false;
    private boolean renderOnRowSelectFORDETAIL = false;
    private int indexForMenu = 0;
    //private List<String> elementsSmall;
    //private List<String> droppedCars;
    //------------------------------------------------------------------------------------------------------------------
    //------------------------------------------------------------------------------------------------------------------
    //------------------------------------------------------------------------------------------------------------------
    //------------------------------------------------------------------------------------------------------------------
    //------------------------------------------------------------------------------------------------------------------
    //------------------------------------------------------------------------------------------------------------------
    //------------------------------------------------------------------------------------------------------------------
    //------------------------------------------------------------------------------------------------------------------
    //private String[] colors;
    //private String[] manufacturers;
    private List<Element> carsSmall;
    private List<Element> droppedCars;
    private Element selectedCar;
    private String refExample = "";

    /*private void populateRandomCars(List<Car> list, int size) {
     for (int i = 0; i < size; i++) {
     list.add(new Car(getRandomModel(), getRandomYear(), getRandomManufacturer(), getRandomColor()));
     }
     }*/
    public List<Element> getCarsSmall() {
        return carsSmall;
    }

    /*private int getRandomYear() {
     return (int) (Math.random() * 50 + 1960);
     }*/

    /*private String getRandomColor() {
     return colors[(int) (Math.random() * 10)];
     }

     private String getRandomManufacturer() {
     return manufacturers[(int) (Math.random() * 10)];
     }*/

    /*private String getRandomModel() {
     return UUID.randomUUID().toString().substring(0, 8);
     }*/
    public void offCarDrop() {
        droppedCars.remove(selectedCar);
        
        if (selectedCar.getContent().equals("Colon :") || selectedCar.getContent().equals("Semicolon ;") || selectedCar.getContent().equals("SPACE") || selectedCar.getContent().equals("Quotation \"") || selectedCar.getContent().equals("Full Stop .") || selectedCar.getContent().equals("Comma ,")) {
        } else {
        carsSmall.add(selectedCar);
        }

        updateRefExample();
    }
    
    public void updateRefExample()
    {
        refExample = "";

        for (Element zzz : droppedCars) {
            //refExample += zzz.getContent();
            if (zzz.getContent().equals("Colon :")) {
                refExample += ":";
            } else if (zzz.getContent().equals("Semicolon ;")) {
                refExample += ";";
            } else if (zzz.getContent().equals("Quotation \"")) {
                refExample += "\"";
            } else if (zzz.getContent().equals("SPACE")) {
                refExample += " ";
            } else if (zzz.getContent().equals("Full Stop .")) {
                refExample += ".";
            } else if (zzz.getContent().equals("Comma ,")) {
                refExample += ","; 
            } else {
                refExample += zzz.getContent();
            } 
        }
    }
    
    public void carBold() {
        //selectedCar.setName("<p style=\"font-weight: bold\">"+selectedFormat.getName()+"</p>"); //style="font-weight: bold"
        int i = droppedCars.indexOf(selectedCar);
        //droppedCars.remove(i);
        //selectedCar.setContent("<b>"+selectedCar.getContent()+"</b>");
        String demo = "";
        if (selectedCar.getContent().equals("Colon :")) {
                demo += ":";
            } else if (selectedCar.getContent().equals("Semicolon ;")) {
                demo += ";";
            } else if (selectedCar.getContent().equals("Quotation \"")) {
                demo += "\"";
            } else if (selectedCar.getContent().equals("SPACE")) {
                demo += " ";
            } else if (selectedCar.getContent().equals("Full Stop .")) {
                demo += ".";
            } else if (selectedCar.getContent().equals("Comma ,")) {
                demo += ","; 
            } else {
                demo += selectedCar.getContent();
            }  
        
        // sooo stuffed 
                
        droppedCars.get(i).setBold(!selectedCar.isBold());         
        if(selectedCar.isBold())
        droppedCars.get(i).setContent("<b>"+demo+"</b>");
        else
        droppedCars.get(i).setContent(demo);
           
        //selectedCar.setBold(true);
        updateRefExample();  
        //droppedCars.add(i, selectedCar); 
        /*int icount = 0;
        for (Element zzz : droppedCars) {
            
            if (icount==i)
                droppedCars.get(i).setContent(city);
                icount++;
        }*/
    } 
    public void carUnderline() { 
        
    }
    public void carItalic() {
        
    }

    public void onCarDrop(DragDropEvent ddEvent) {
        Element car = ((Element) ddEvent.getData());

        if (droppedCars.contains(car)) {
            droppedCars.add(new Element(car.getContent()));
        } else {
            droppedCars.add(car);
        }



        if (car.getContent().equals("Colon :") || car.getContent().equals("Semicolon ;") || car.getContent().equals("SPACE") || car.getContent().equals("Quotation \"") || car.getContent().equals("Full Stop .") || car.getContent().equals("Comma ,")) {
        } else {
            carsSmall.remove(car);
        }


        if (car.getContent().equals("Colon :")) {
            refExample += ":"; 
        } else if (car.getContent().equals("Semicolon ;")) {
            refExample += ";";
        } else if (car.getContent().equals("Quotation \"")) {
            refExample += "\"";
        } else if (car.getContent().equals("SPACE")) {
            refExample += " ";
        } else if (car.getContent().equals("Full Stop .")) {
            refExample += ".";
        } else if (car.getContent().equals("Comma ,")) {
            refExample += ",";
        } else {
            refExample += car.getContent();
        }



    }

     public String converBooleanToHuman(Boolean bool){
         if(bool == true)
             return "Yes";
         else
             return "No";
     }
    
    public List<Element> getDroppedCars() {
        return droppedCars;
    }

    //------------------------------------------------------------------------------------------------------------------
    //------------------------------------------------------------------------------------------------------------------
    //------------------------------------------------------------------------------------------------------------------
    //------------------------------------------------------------------------------------------------------------------
    //------------------------------------------------------------------------------------------------------------------
    /*public void onCarDrop(DragDropEvent ddEvent) {
     String car = ((String) ddEvent.getData());

     droppedCars.add(car);
     elementsSmall.remove(car);
     }*/
    public void changeindexForMenu(int i) {
        ////System.out.println(i); 
        indexForMenu = i;
    }

    public String gotoLogin() {
        indexForMenu = 100;
        return "login.jsf?faces-redirect=true";
    }

    public String gotoCreate() {
        indexForMenu = 100;
        return "create.jsf?faces-redirect=true";
    }

    public String gotoeditAccount() {
        indexForMenu = 100;
        return "editAccount.jsf?faces-redirect=true";
    }

    public void onRowSelect() {
        renderOnRowSelect = true;
    }

    public void onRowUnselect() {
        renderOnRowSelect = false;
    }

    public void onRowSelectREF() {
        renderOnRowSelectREF = true;
    }

    public void onRowUnselectREF() {
        renderOnRowSelectREF = false;
    }

    public void onRowSelectFORDETAIL() {
        renderOnRowSelectFORDETAIL = true;
    }

    public void onRowUnselectFORDETAIL() {
        renderOnRowSelectFORDETAIL = false;
    }

    public void onRowSelectSET() {
        renderOnRowSelectSET = true;
    }

    public void onRowUnselectSET() {
        renderOnRowSelectSET = false;
    }

    public void onRowSelectFOR() {
        renderOnRowSelectFOR = true;
    }

    public void onRowUnselectFOR() {
        renderOnRowSelectFOR = false;
    }

    public void renderType() {

        carsSmall.clear();
        droppedCars.clear();

        if (getType().equals("book")) {
            carsSmall.add(new Element("Colon :"));
            carsSmall.add(new Element("Semicolon ;"));
            carsSmall.add(new Element("SPACE"));
            carsSmall.add(new Element("Full Stop ."));
            carsSmall.add(new Element("Comma ,"));
            carsSmall.add(new Element("Quotation \""));
            carsSmall.add(new Element("Title"));
            carsSmall.add(new Element("Year"));
            carsSmall.add(new Element("City"));
            carsSmall.add(new Element("Isbn10"));
            carsSmall.add(new Element("Isbn13"));
            carsSmall.add(new Element("Pages"));
        } else if (getType().equals("edbook")) {
            carsSmall.add(new Element("Colon :"));
            carsSmall.add(new Element("Semicolon ;"));
            carsSmall.add(new Element("SPACE"));
            carsSmall.add(new Element("Full Stop ."));
            carsSmall.add(new Element("Comma ,"));
            carsSmall.add(new Element("Quotation \""));
            carsSmall.add(new Element("Title"));
            carsSmall.add(new Element("Year"));
            carsSmall.add(new Element("City"));
            carsSmall.add(new Element("Isbn10"));
            carsSmall.add(new Element("Isbn13"));
            carsSmall.add(new Element("Pages"));
            carsSmall.add(new Element("Edition"));
        } else if (getType().equals("journal")) {
            carsSmall.add(new Element("Colon :"));
            carsSmall.add(new Element("Semicolon ;"));
            carsSmall.add(new Element("SPACE"));
            carsSmall.add(new Element("Full Stop ."));
            carsSmall.add(new Element("Comma ,"));
            carsSmall.add(new Element("Quotation \""));
            carsSmall.add(new Element("Title"));
            carsSmall.add(new Element("Year"));
            carsSmall.add(new Element("Url"));
            carsSmall.add(new Element("Issue"));
            carsSmall.add(new Element("Isbn10"));
            carsSmall.add(new Element("Volume"));
            carsSmall.add(new Element("Pages"));
            carsSmall.add(new Element("Doi"));
        } else if (getType().equals("conference")) {
            carsSmall.add(new Element("Colon :"));
            carsSmall.add(new Element("Semicolon ;"));
            carsSmall.add(new Element("SPACE"));
            carsSmall.add(new Element("Full Stop ."));
            carsSmall.add(new Element("Comma ,"));
            carsSmall.add(new Element("Quotation \""));
            carsSmall.add(new Element("Title"));
            carsSmall.add(new Element("Year"));
            carsSmall.add(new Element("Date"));
            carsSmall.add(new Element("City"));
        } else if (getType().equals("website")) {
            carsSmall.add(new Element("Colon :"));
            carsSmall.add(new Element("Semicolon ;"));
            carsSmall.add(new Element("SPACE"));
            carsSmall.add(new Element("Full Stop ."));
            carsSmall.add(new Element("Comma ,"));
            carsSmall.add(new Element("Quotation \""));
            carsSmall.add(new Element("Title"));
            carsSmall.add(new Element("Year"));
            carsSmall.add(new Element("Date"));
            carsSmall.add(new Element("Url"));
        } else if (getType().equals("mediaStill")) {
            carsSmall.add(new Element("Colon :"));
            carsSmall.add(new Element("Semicolon ;"));
            carsSmall.add(new Element("SPACE"));
            carsSmall.add(new Element("Full Stop ."));
            carsSmall.add(new Element("Comma ,"));
            carsSmall.add(new Element("Quotation \""));
            carsSmall.add(new Element("Title"));
            carsSmall.add(new Element("Year"));
            carsSmall.add(new Element("Date"));
            carsSmall.add(new Element("Url"));
        } else if (getType().equals("mediaMotion")) {
            carsSmall.add(new Element("Colon :"));
            carsSmall.add(new Element("Semicolon ;"));
            carsSmall.add(new Element("SPACE"));
            carsSmall.add(new Element("Full Stop ."));
            carsSmall.add(new Element("Comma ,"));
            carsSmall.add(new Element("Quotation \""));
            carsSmall.add(new Element("Title"));
            carsSmall.add(new Element("Year"));
            carsSmall.add(new Element("Date"));
            carsSmall.add(new Element("Url"));
        } else if (getType().equals("mediaAudio")) {
            carsSmall.add(new Element("Colon :"));
            carsSmall.add(new Element("Semicolon ;"));
            carsSmall.add(new Element("SPACE"));
            carsSmall.add(new Element("Full Stop ."));
            carsSmall.add(new Element("Comma ,"));
            carsSmall.add(new Element("Quotation \""));
            carsSmall.add(new Element("Title"));
            carsSmall.add(new Element("Year"));
            carsSmall.add(new Element("Url"));
            carsSmall.add(new Element("Date"));
        }
    }

    public void display() {
        renderEdition = false;
        renderCity = false;
        renderDoi = false;
        renderIsbn = false;
        renderPages = false;
        renderVolume = false;
        renderIssue = false;
        renderUrl = false;
        renderDate = false;

        if (getType().equals("book")) {
            renderCity = true;
            renderIsbn = true;
            renderPages = true;
        } else if (getType().equals("edbook")) {
            renderCity = true;
            renderIsbn = true;
            renderPages = true;
            renderEdition = true;
        } else if (getType().equals("journal")) {
            renderDoi = true;
            renderPages = true;
            renderVolume = true;
            renderIssue = true;
            renderUrl = true;
        } else if (getType().equals("conference")) {
            renderDate = true;
            renderCity = true;
        } else if (getType().equals("website")) {
            renderUrl = true;
            renderDate = true;
        } else if (getType().equals("mediaStill")) {
            renderUrl = true;
            renderDate = true;
        } else if (getType().equals("mediaMotion")) {
            renderUrl = true;
            renderDate = true;
        } else if (getType().equals("mediaAudio")) {
            renderUrl = true;
            renderDate = true;
        }
    }

    public void display(String type) {
        renderEdition = false;
        renderCity = false;
        renderDoi = false;
        renderIsbn = false;
        renderPages = false;
        renderVolume = false;
        renderIssue = false;
        renderUrl = false;
        renderDate = false;

        if (type.equals("book")) {
            renderCity = true;
            renderIsbn = true;
            renderPages = true;
        } else if (type.equals("edbook")) {
            renderCity = true;
            renderIsbn = true;
            renderPages = true;
            renderEdition = true;
        } else if (type.equals("journal")) {
            renderDoi = true;
            renderPages = true;
            renderVolume = true;
            renderIssue = true;
            renderUrl = true;
        } else if (type.equals("conference")) {
            renderDate = true;
            renderCity = true;
        } else if (type.equals("website")) {
            renderUrl = true;
            renderDate = true;
        } else if (type.equals("mediaStill")) {
            renderUrl = true;
            renderDate = true;
        } else if (type.equals("mediaMotion")) {
            renderUrl = true;
            renderDate = true;
        } else if (type.equals("mediaAudio")) {
            renderUrl = true;
            renderDate = true;
        }
    }
    public boolean checkIfTenOrMore(String sss) {
        if (sss.equals("ref")) {
            ////System.out.println(current.getRefs().size());
            if (current.getRefs().size() > 9) {
                return true;
            } else {
                return false;
            }
        } else if (sss.equals("aut")) {
            if (current.getAuthors().size() > 9) {
                return true;
            } else {
                return false;
            }
        } else if (sss.equals("set")) {
            ////System.out.println(current.getPublications().size());
            if (current.getPublications().size() > 9) {
                return true;
            } else {
                return false;
            }
        } else if (sss.equals("format")) {
            ////System.out.println(current.getPublications().size());
            if (current.getFormats().size() > 9) {
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
        //return false;
    }

    public String gotodetailsSet() {
        if (selectedAcademicSet != null) {
            return "detailsSet.jsf?faces-redirect=true";
        } else {
            return "veiwSets.jsf?faces-redirect=true";
        }
    }

    public String gotodetailsFor() {
        if (selectedFormat != null) {
            return "detailsFormat.jsf?faces-redirect=true";
        } else {
            return "veiwFormats.jsf?faces-redirect=true";
        }
    }

    public boolean gethasPub() {
        return hasPub;
    }

    public String getSelectedAcademicSetNameForRename() {
        //if (!selectedAcademicSet.getName().equals(null))
        try {
            selectedAcademicSetNameForRename = selectedAcademicSet.getName();
        } catch (Exception e) {
        } finally {
            return selectedAcademicSetNameForRename;
        }

    }

    public String getSelectedFormatNameForRename() {
        //if (!selectedAcademicSet.getName().equals(null))
        try {
            selectedFormatNameForRename = selectedFormat.getName();
        } catch (Exception e) {
        } finally {
            return selectedFormatNameForRename;
        }

    }

    public void setSelectedAcademicSetNameForRename(String selectedAcademicSetNameForRename) {

        this.selectedAcademicSetNameForRename = selectedAcademicSetNameForRename;
    }

    public void setSelectedFormatNameForRename(String selectedFormatNameForRename) {
        this.selectedFormatNameForRename = selectedFormatNameForRename;
    }

    public String selectedAcademicSetDelete() {
        ////System.out.println("GREEN");
        Userservice.deleteSelectedAcademicSet(selectedAcademicSet, current);
        current.deletePublications(selectedAcademicSet.getId());

        FacesContext context = FacesContext.getCurrentInstance();
        context.addMessage(null, new FacesMessage("Successful", "AcademicSet had been deleted"));
        return "viewSets.jsf?faces-redirect=true";

    }

    public String selectedFormatDelete() {
        Userservice.deleteSelectedFormat(selectedFormat, current);
        current.deleteFormat(selectedFormat.getId());

        FacesContext context = FacesContext.getCurrentInstance();
        context.addMessage(null, new FacesMessage("Successful", "Format had been deleted"));
        return "viewSets.jsf?faces-redirect=true";

    }

    public String selectedAcademicSetRename() {
        ////System.out.println("RED");

        try {
            ////System.out.println(selectedAcademicSet.getName());
        } catch (Exception e) {
            ////System.out.println("It dint select!!!!!!!!!!!!!!!!!!!!!");
        }
        Userservice.renameSelectedAcademicSet(selectedAcademicSet, selectedAcademicSetNameForRename);
        selectedAcademicSetNameForRename = "";

        return "viewSets.jsf?faces-redirect=true";
    }

    public String selectedFormatRename() {
        ////System.out.println("RED");

        try {
            ////System.out.println(selectedAcademicSet.getName());
        } catch (Exception e) {
            ////System.out.println("It dint select!!!!!!!!!!!!!!!!!!!!!");
        }
        Userservice.renameSelectedFormat(selectedFormat, selectedFormatNameForRename);
        selectedFormatNameForRename = "";

        return "viewFormats.jsf?faces-redirect=true";
    }

    public String removeSelectedSetReference() {
        selectedAcademicSet = Userservice.removeRefToSet(selectedAcademicSet, selectedSetReference);
        return "detailsSet.jsf?faces-redirect=true";
    }

    public String addReferenceToSet() {
        selectedAcademicSet = Userservice.addRefToSet(selectedAcademicSet, selectedReferenceFromAll);
        return "detailsSet.jsf?faces-redirect=true";
    }

    public String addAcademicSet() {

        current = Userservice.addAcademicSet(current.getId(), selectedAcademicSetName);
        //AcademicSet as = new AcademicSet(selectedAcademicSetName);
        //current.addAcademicSet();
        selectedAcademicSetName = "";

        return "viewSets.jsf?faces-redirect=true";
    }

    public String addFormat() {


        System.out.print(currentFormat.getName() + "test");
        
        current = Userservice.addFormat(current.getId(), currentFormat);
        currentFormat.setName(""); 
        return "viewFormats.jsf?faces-redirect=true";
    }

    public String unlinkAuthor() {
        selectedReference = Userservice.unlinkAuthor(selectedReference, selectedAuthor);
        return "detailsREF.jsf?faces-redirect=true";
    }

    public String unlinkTAuthor() {
        selectedReference = Userservice.unlinkTAuthor(selectedReference, selectedTranslator);
        return "detailsREF.jsf?faces-redirect=true";
    }

    public String gotoLinkA() {
        return "linkA.jsf?faces-redirect=true";
    }

    public String gotoLinkTA() {
        return "linkT.jsf?faces-redirect=true";
    }

    public String linkAuthor() {
        Author newAuthor;
        //   if (number1 == 1) {
        String txt11 = txt1.substring(0, txt1.indexOf(' '));
        newAuthor = Userservice.searchbByANAME(txt11);
        selectedReference = Userservice.linkAuthor(selectedReference, newAuthor);
        //authorslist.add(newAuthor);
        //  }//else

        txt1 = "";


        return "detailsREF.jsf?faces-redirect=true";


    }

    public String linkTAuthor() {
        Translator newAuthor;
        // if (number1 == 1) {
        String txt11 = txt1.substring(0, txt1.indexOf(' '));
        newAuthor = Userservice.searchbByANAMEtrans(txt11);
        selectedReference = Userservice.linkTAuthor(selectedReference, newAuthor);
        //  }
        txt1 = "";
        return "detailsREF.jsf?faces-redirect=true";
    }

    public String getSample(String[] s) {
        String temp = "";
        for (String eas : s) {
            if (eas.equals(s[s.length - 1])) {
                temp += eas;
            } else {
                temp += eas + ", ";
            }

        }
        return temp;
    }

    public void setSample(String sample) {
        this.sample = sample;
    }

    public String addEditPub() {
        //Publisher p = new Publisher(SelectedReferencePub, SelectedReferencePubcountry);
        //selectedReference.setPublisher(p); 


        selectedReference = Userservice.addPublisher(oldPubID, selectedReference.getId(), SelectedReferencePub, SelectedReferencePubcountry); //if -111 ceate else edit PUB addEditPub();
        if (selectedReference.getPublisher() != null) {
            hasPub = true;
        }
        return "detailsREF.jsf?faces-redirect=true";
    }

    public String deletePub() {
        Userservice.deletePub(selectedReference.getPublisher().getName(), selectedReference.getPublisher().getCountry(), selectedReference);
        selectedReference.deletePub();
        hasPub = false;
        FacesContext context = FacesContext.getCurrentInstance();
        context.addMessage(null, new FacesMessage("Successful", "Publisher had been deleted"));
        return "detailsREF.jsf?faces-redirect=true";
    }

    public String gotoEditReference() {

        if (!(selectedReference == null)) {
            display(selectedReference.getType());

            return "editReference.jsf?faces-redirect=true";
        } else {
            return "false";
        }

    }

    public String editReference() {


        Userservice.updateReference(selectedReference);
        return "viewReferences.jsf?faces-redirect=true";


    }

    public String deleteReference() {
        current.getRefs();
        Userservice.deleteReference(current.getEmail(), selectedReference.getId());
        current.deleteReference(selectedReference.getId());
        FacesContext context = FacesContext.getCurrentInstance();
        context.addMessage(null, new FacesMessage("Successful", "Reference had been deleted"));
        return "viewReferences.jsf?faces-redirect=true";
    }

    public String gotoNewReference() {
        try {
            title = "";
            rYear = "";
            edition = "";
            city = "";
            doi = "";
            isbn10 = "";
            isbn13 = "";
            eisbn13 = "";
            //authorslist.clear();
            //translatorlist.clear();
            type = "";
            pages = "";
            volume = "";
            issue = "";
            address = "";
            date = "";
            other = "";
            language = "";
            subject = "";
            //countAuthorlistSize = 0;
            //countTranslatorlistSize = 0;
            return "newReference.jsf?faces-redirect=true";
        } catch (Exception e) {
            return "newReference.jsf?faces-redirect=true";
        }
    }

    public String getSelectedReferencePub() {
        try {
            String s = selectedReference.getPublisher().getName();
            oldPubID = selectedReference.getPublisher().getId();
            return s;
        } catch (Exception e) {
        }
        oldPubID = -111;
        return "";
    }

    public String getSelectedReferencePubcountry() {
        try {
            String s = selectedReference.getPublisher().getCountry();
            oldPubID = selectedReference.getPublisher().getId();
            return s;
        } catch (Exception e) {
        }
        oldPubID = -111;
        return "";
    }

    public void setSelectedReferencePub(String SelectedReferencePub) {
        /*if (selectedReference.getPublisher().getName()==null) 
         Userservice.addPublisher(String,selectedReference.getId()); //1=create new PUB and link, 2=edit PUB*/
        if (this.SelectedReferencePub == null) {
            oldPubID = -111;
        }
        this.SelectedReferencePub = SelectedReferencePub;
    }

    public void setSelectedReferencePubcountry(String SelectedReferencePubcountry) {
        if (this.SelectedReferencePubcountry == null) {
            oldPubID = -111;
        }
        this.SelectedReferencePubcountry = SelectedReferencePubcountry;
    }

    public String gotoViewReference() {
        ////System.out.println(hasPub);
        if (selectedReference.getPublisher() != null) {
            ////System.out.println(hasPub);
            hasPub = true;
            ////System.out.println(hasPub);
        }
        return "detailsREF.jsf?faces-redirect=true";
    }
    private Map<String, String> types = new HashMap<String, String>();

    public UserBean() {
        types.put("book", "book");
        types.put("edbook", "edbook");
        types.put("journal", "journal");
        types.put("conference", "conference");
        types.put("website", "website");
        types.put("mediaStill", "mediaStill");
        types.put("mediaMotion", "mediaMotion");
        types.put("mediaAudio", "mediaAudio");

        languages.put("Arabic", "Arabic");
        languages.put("Bengali", "Bengali");
        languages.put("Cantonese", "Cantonese");
        languages.put("English", "English");
        languages.put("French", "French");
        languages.put("German", "German");
        languages.put("Gujarati", "Gujarati");
        languages.put("Hindi", "Hindi");
        languages.put("Italian", "Italian");
        languages.put("Japanese", "Japanese"); //julia's code


        languages.put("Javanese", "Javanese");
        languages.put("Jin", "Jin");
        languages.put("Korean", "Korean");
        languages.put("Malay/Indonesian", "Malay/Indonesian");
        languages.put("Mandarin", "Mandarin");
        languages.put("Marathi", "Marathi");
        languages.put("Min Nan", "Min Nan");
        languages.put("Persian", "Persian");
        languages.put("Polish", " Polish");
        languages.put("Portuguese", "Portuguese"); //brian's code

        languages.put("Punjabi", "Punjabi");
        languages.put("Russian", "Russian");
        languages.put("Spanish", "Spanish");
        languages.put("Tamil", "Tamil");
        languages.put("Telugu", "Telugu");
        languages.put("Thai", "Thai");
        languages.put("Turkish", "Turkish");
        languages.put("Urdu", "Urdu");
        languages.put("Vietnamese", " Vietnamese");
        languages.put("Wu", "Wu"); //Patience's code

        carsSmall = new ArrayList<Element>();
        droppedCars = new ArrayList<Element>();


        /*elementsSmall = new ArrayList<String>();
         droppedCars = new ArrayList<String>();*/

        carsSmall.add(new Element("Colon :"));
        carsSmall.add(new Element("Semicolon ;"));
        carsSmall.add(new Element("SPACE"));
        carsSmall.add(new Element("Full Stop ."));
        carsSmall.add(new Element("Comma ,"));
        carsSmall.add(new Element("Quotation \""));


        /*colors = new String[10];
         colors[0] = "Black";
         colors[1] = "White";
         colors[2] = "Green";
         colors[3] = "Red";
         colors[4] = "Blue";
         colors[5] = "Orange";
         colors[6] = "Silver";
         colors[7] = "Yellow";
         colors[8] = "Brown";
         colors[9] = "Maroon";

         manufacturers = new String[10];
         manufacturers[0] = "Mercedes";
         manufacturers[1] = "BMW";
         manufacturers[2] = "Volvo";
         manufacturers[3] = "Audi";
         manufacturers[4] = "Renault";
         manufacturers[5] = "Opel";
         manufacturers[6] = "Volkswagen";
         manufacturers[7] = "Chrysler";
         manufacturers[8] = "Ferrari";
         manufacturers[9] = "Ford";*/

    }

    /* @PostConstruct
     public void init() { 
 
     populateRandomCars(carsSmall, 9);
     }*/
    public Map<String, String> getTypes() {
        return types;
    }

    public void setTypes(Map<String, String> types) {
        this.types = types;
    }

    public String getType() {
        return type;
    }

    public List<Reference> getallReferences() {
        //Set<Reference> sss = Userservice.getAllRef(current.getId());
        List<Reference> aaa = Userservice.getAllRef(current.getId());

        //List<String> list = asSortedList((Collection)aaa); 

        return aaa;

        //return Userservice.getAllUser();  


    }

    /*public static <T extends Comparable<? super T>> List<T> asSortedList(Collection<T> c) {
     List<T> list = new ArrayList<T>(c);
     Collections.sort(list);
     return list;
     }*/
    public List<Reference> getallSetReferences() {
        //Set<Reference> sss = Userservice.getAllSETRef(current.getId());
        //List<Reference> aaa = new ArrayList<Reference>(sss);
        List<Reference> aaa = new ArrayList<Reference>(selectedAcademicSet.getReferencess());

        return aaa;

        //return Userservice.getAllUser(); 


    }

    /*public void clearIN(int inn1) {
     if (in1 == 1) {
     in1 = '\0';
     }
     }*/
    public String getPages() {
        return pages;
    }

    public void setPages(String pages) {
        this.pages = pages;
    }

    public String editAuthor() {

        char in1 = ' ';
        char in2 = ' ';
        char in3 = ' ';
        char in4 = ' ';
        char in5 = ' ';

        if (!"".equals(aname1)) {
            in1 = aname1.charAt(0);
        }
        if (!"".equals(aname2)) {
            in2 = aname2.charAt(0);
        }
        if (!"".equals(aname3)) {
            in3 = aname3.charAt(0);
        }
        if (!"".equals(aname4)) {
            in4 = aname4.charAt(0);
        }
        if (!"".equals(aname5)) {
            in5 = aname5.charAt(0);
        }






        char[] srcArray2 = {in1, in2, in3, in4, in5};
        String[] names = {aname1, aname2, aname3, aname4, aname5};
        selectedAuthor.setInitials(srcArray2);
        selectedAuthor.setNames(names);
        Userservice.updateAuthor(selectedAuthor);



        return "viewAuthors.jsf?faces-redirect=true";
    }

    public String gotoEditAuthor() {
        return "editAuthor.jsf?faces-redirect=true";
    }

    public String gotoAddAuthor() {
        aname1 = "";
        aname2 = "";
        aname3 = "";
        aname4 = "";
        aname5 = "";

        return "newAuthor.jsf?faces-redirect=true";
    }

    public String deleteAuthor() {
        current.getAuthors();
        Userservice.deleteAuthor(current.getEmail(), selectedAuthor.getId());
        current.deleteAuthor(selectedAuthor.getId());
        FacesContext context = FacesContext.getCurrentInstance();
        context.addMessage(null, new FacesMessage("Successful", "Author had been deleted"));
        return "viewAuthor.jsf?faces-redirect=true";
    }

    public List<Translator> getallTranslatirsOfthisRef() {
        Set<Translator> sss = selectedReference.getTranslators();
        List<Translator> aaa = new ArrayList<Translator>(sss);
        return aaa;
    }

    public List<Author> getallAuthorsOfthisRef() {
        Set<Author> sss = selectedReference.getAuthors();
        List<Author> aaa = new ArrayList<Author>(sss);


        return aaa;
    }

    public List<Author> getallAuthors() {
        current = Userservice.searchbByEmail(current.getEmail());
        //Set<Author> sss = Userservice.getallAuthors(current.getId());
        List<Author> aaa = Userservice.getallAuthors(current.getId());


        return aaa;

        //return Userservice.getAllUser();  


    }

    public String changeUser() {

        String hexString1 = "";

        //DateFormat df = new SimpleDateFormat("dd/MM/yy");
        //String formattedDate = df.format(new Date());

        current = Userservice.searchbByEmail(email);
        AccUser user = current;
        String formattedDate = user.getSalt();
        MessageDigest md;
        String passwordHash = currentpassword + formattedDate;

        /////////////////////////////http://www.mkyong.com/java/java-sha-hashing-example/

        try {
            md = MessageDigest.getInstance("SHA-256");

            md.update(passwordHash.getBytes());

            byte byteData[] = md.digest();

            //convert the byte to hex format method 1
            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < byteData.length; i++) {
                sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
            }

            ////System.out.println("Hex format : " + sb.toString());

            //convert the byte to hex format method 2
            StringBuffer hexString = new StringBuffer();
            for (int i = 0; i < byteData.length; i++) {
                String hex = Integer.toHexString(0xff & byteData[i]);
                if (hex.length() == 1) {
                    hexString.append('0');
                }
                hexString.append(hex);
            }
            ////System.out.println("Hex format : " + hexString.toString());


            hexString1 = hexString.toString();

        } catch (NoSuchAlgorithmException ex) {
            Logger.getLogger(DataAccess.class.getName()).log(Level.SEVERE, null, ex);
        }

        if ((!Userservice.UserExist(current.getId(), email)) && (hexString1.equals(current.getPassword()))) {
            Userservice.updateUser(current.getId(), name, email, password);
            current.setName(name);
            current.setEmail(email);
        } else {
            error = "Email_already_exist";
            return "error.jsf?faces-redirect=true&Error=Email_already_exist_or_not_right_Password";
        }

        return "home?faces-redirect=true";
    }

    public String addPublication() {
        return "page319.jsf?faces-redirect=true";
    }

    /*public String addAuthorTraslator() {
     Author newAuthor;
     //char[] srcArray;


     if (number1 == 1) {
     String txt11 = txt1.substring(0, txt1.indexOf(' '));
     newAuthor = Userservice.searchbByANAME(txt11);
     translatorlist.add(newAuthor);
     //srcArray = newAuthor.getInitials();

     }



     //Userservice.addAuthor(email, newAuthor);
     txt1 = "";
     return "page319.jsf?faces-redirect=true";
     }*/
    //this is to add a Autor with process of adding a Ref
       /* public String addAuthor() {

     Author newAuthor;
     //char[] srcArray;


     if (number1 == 1) {
     String txt11 = txt1.substring(0, txt1.indexOf(' '));
     newAuthor = Userservice.searchbByANAME(txt11);
     authorslist.add(newAuthor);
     //srcArray = newAuthor.getInitials();

     } else {
     newAuthor = Userservice.searchbByASURNAME(txt2);
     //srcArray = newAuthor.getInitials();
     }



     //Userservice.addAuthor(email, newAuthor);
     txt1 = "";
     return "page319.jsf?faces-redirect=true";

     }*/
    //this is to add a Autor with main nav
    public String addAuthor2() {

        char in1 = ' ';
        char in2 = ' ';
        char in3 = ' ';
        char in4 = ' ';
        char in5 = ' ';

        if (!"".equals(aname1)) {
            in1 = aname1.charAt(0);
        }
        if (!"".equals(aname2)) {
            in2 = aname2.charAt(0);
        }
        if (!"".equals(aname3)) {
            in3 = aname3.charAt(0);
        }
        if (!"".equals(aname4)) {
            in4 = aname4.charAt(0);
        }
        if (!"".equals(aname5)) {
            in5 = aname5.charAt(0);
        }

        char[] srcArray2 = {in1, in2, in3, in4, in5};
        String[] names = {aname1, aname2, aname3, aname4, aname5};
        
        

        
        String temp = Character.toUpperCase(asname.charAt(0)) + asname.substring(1);
        asname = temp;
        temp = Character.toUpperCase(aname.charAt(0)) + aname.substring(1);
        aname = temp;
        Author newAuthor = new Author(asname, aname, srcArray2, names);//md5 not good enough
        //List<Author> a = new ArrayList<Author>();
        //a.add(newAuthor); 

        current.addAuthor(newAuthor);

        Userservice.addAuthor(email, newAuthor);  //i first pessit manully then make link

        asname = "";
        aname = "";
        aname1 = "";
        aname2 = "";
        aname3 = "";
        aname4 = "";
        aname5 = "";

        return "viewAuthors.jsf?faces-redirect=true";
    }

    public List<String> complete(String query) {
        /*List<Author> results2 = Userservice.getAllAuthors();//new ArrayList<String>(); 
         Iterator it = results2.iterator();
         List<String> results = new ArrayList();
         while (it.hasNext()) {
         Author tmp = (Author) it.next();
         results.add(tmp.getName() + " " + tmp.getSurname());
         }

         return results;*/ //  <-- this, BIG NOTE, SHOW PAULA 222i got it right for user to use other users’s autoer without allowing them to changethe

        //current.getAuthors();

        List<Author> aaa = new ArrayList<Author>(current.getAuthors());
        Iterator it = aaa.iterator();
        List<String> results = new ArrayList();
        while (it.hasNext()) {
            Author tmp = (Author) it.next();
            results.add(tmp.getName() + " " + tmp.getSurname());
        }
        return results;
    }

    public String createRef() {
        // User newUser = new User(name,email,rights);
        // Userservice.addUser(newUser);
        //return "home?faces-redirect=true";
        //http://crackstation.net/hashing-security.htm
        DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
        if (date2 != null) {
            date = df.format(date2);
        } else {
            date = "";
        }

        Reference newRef = new Reference(title, rYear, edition, city, doi, isbn10, isbn13, eisbn13, type, pages, volume, issue, address, date, other, language, subject);//md5 not good enough
        //newRef.setPublisher(pname);


        //Publisher p = new Publisher(pname, pcountry);

        ///testing
        /*newRef.setEdition(txt1);
         Author newAuthor = Userservice.searchbByANAME(txt1);
         a.add(newAuthor);*/
        ///testing

        /*Iterator it = a.iterator();
         while (it.hasNext()) {
         Author tmp = (Author) it.next();
         newRef.addAuthor(tmp);
         }*/
        //Author newAuthor2;
        //char[] srcArray;
        /*char[] srcArray2 = {in1, in2, in3, in4, in5};
         newAuthor2 = new Author(asname,aname, srcArray2);*/
        /*for (Author test : authorslist)
         newRef.addAuthor(test);*/
        //newRef.addAuthor(newAuthor);   
        /*Iterator it2 = at.iterator();
         while (it2.hasNext()) {
         Author tmp = (Author) it2.next();
         newRef.addTranslator(tmp);
         }*/

        //newRef.addAuthor(results);
        //Userservice.addRef(email, newRef);  

        /*newRef.setPublisher(pname);
         newRef.setAuthors(authorslist); 
         p.addReference(newRef); //persist*/

        //Userservice.addPublisher(p);  
        //Userservice.addRef(email, newRef); //i pesist Ref first in dataccess before i add to user



        //Userservice.addRefBig(p, newRef, authorslist, translatorlist, email);
        Userservice.addRefBig(newRef, email);
        current.addReference(newRef);

        //authorslist.clear();
        //translatorlist.clear();

        //countAuthorlistSize = 0;
        //countTranslatorlistSize = 0;

        return "viewReferences?faces-redirect=true";
    }

    public String getlogin() {///http://stackoverflow.com/questions/3841361/jsf-http-session-login/3842060#3842060
        //if (!email.equals("")) {
        // AccUser user = Userservice.searchbByEmail(email);



        //current = user;

        // if (current == null) {
           /* if (current == null) {
         return "false";
         } else {
         login = true;
         login2 = false;*/
        return String.valueOf(login);
        // }
        // }
        //return "false";

    }

    public boolean isLoggedIn() {
        return current != null;
    }

    public String logout() {
        FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
        email = "";
        current = null;
        login = false;
        login2 = true;
        return "home?faces-redirect=true";
    }

    public String getcheack() {
        /////////////////////
        //login();


        /////////////////////////////http://www.mkyong.com/java/java-sha-hashing-example/


        ////////////////////

        try {
            current = Userservice.searchbByEmail(email);
            AccUser user = current;
            String formattedDate = user.getSalt();
            MessageDigest md;
            String password2 = password + formattedDate;

            //////////////////////////////
            md = MessageDigest.getInstance("SHA-256");

            md.update(password2.getBytes());

            byte byteData[] = md.digest();

            //convert the byte to hex format method 1
            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < byteData.length; i++) {
                sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
            }

            ////System.out.println("Hex format : " + sb.toString());

            //convert the byte to hex format method 2
            StringBuffer hexString = new StringBuffer();
            for (int i = 0; i < byteData.length; i++) {
                String hex = Integer.toHexString(0xff & byteData[i]);
                if (hex.length() == 1) {
                    hexString.append('0');
                }
                hexString.append(hex);
            }
            ////System.out.println("Hex format : " + hexString.toString());
            //////////////////////////////

            if (hexString.toString().equals(user.getPassword()) && user.getEmail().equals(email)) {
                name = current.getName();
                login = true;
                login2 = false;

                indexForMenu = 0;
                return "home?faces-redirect=true"; 
                
           } else {
                error = "Password or email not correct";
                FacesContext context = FacesContext.getCurrentInstance();
                context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_FATAL,"Login Failure", "Email or Password you entered is incorrect!")); 
                return "null";
            }
        } catch (NoSuchAlgorithmException ex) { 
            FacesContext context = FacesContext.getCurrentInstance();
                context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_FATAL,"Login Failure", "Email or Password you entered is incorrect!")); 
                return "null"; 
        } catch (Exception e) {
            FacesContext context = FacesContext.getCurrentInstance();
                context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_FATAL,"Login Failure", "Email or Password you entered is incorrect!")); 
                return "null";
        }
        //if (user1==null)
        //return "error?faces-redirect=true";      
        //return "error?faces-redirect=true&id=sdfsdfsdf";


    }

    /*public String greetUser()
     {
     currentDataAndDate = new java.util.Date();
     return "welcome";
     }*/
    public List<AcademicSet> getallSets() {
        //Set<AcademicSet> ourSets = Userservice.getAllSets(current.getId());
        //Set<AcademicSet> ourSets = Userservice.getAllAcademicSets(current.getId());

        List<AcademicSet> setsAtAll = Userservice.getAllAcademicSets(current.getId());
        return setsAtAll;

    }

    public List<Format> allFormats() {
        List<Format> FFFAtAll = Userservice.allFormats(current.getId());
        return FFFAtAll;
    }

    //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    public int getIndexForMenu() {
        return indexForMenu;
    }

    public String setIndexForMenu(int indexForMenu) {
        //System.out.println(indexForMenu); 
        this.indexForMenu = indexForMenu;
        if (indexForMenu == 0) {
            return "home.jfs?faces-redirect=true";
        } else if (indexForMenu == 1) {
            return "viewAuthors.jfs?faces-redirect=true";
        } else if (indexForMenu == 2) {
            return "viewReferences.jfs?faces-redirect=true";
        } else if (indexForMenu == 3) {
            return "viewSets.jfs?faces-redirect=true";
        } else if (indexForMenu == 4) {
            return "viewFormats.jfs?faces-redirect=true";
        } else if (indexForMenu == 5) {
            return "export.jfs?faces-redirect=true";
        } else if (indexForMenu == 6) {
            return "aboutUs.jfs?faces-redirect=true";
        } else if (indexForMenu == 7) {
            return "contactUs.jfs?faces-redirect=true";
        } else if (indexForMenu == 66) {
            this.indexForMenu = 1;
            return "aboutUs.jfs?faces-redirect=true";
        } else if (indexForMenu == 77) {
            this.indexForMenu = 2;
            return "contactUs.jfs?faces-redirect=true";
        } else {
            return "home.jfs?faces-redirect=true";
        }

    }

    public String getemail() {
        return email;
    }

    public void setemail(String email) {
        this.email = email;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Date getCurrentDataAndDate() {
        return currentDataAndDate;
    }

    public void setCurrentDataAndDate(Date currentDataAndDate) {
        this.currentDataAndDate = currentDataAndDate;
    }

    public AccessInterfaceLocal getUserservice() {
        return Userservice;
    }

    public void setUserservice(AccessInterfaceLocal Userservice) {
        this.Userservice = Userservice;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public AccUser getCurrent() {
        return current;
    }

    public void setCurrent(AccUser current) {
        this.current = current;
    }

    public boolean isLogin() {
        return login;
    }

    public void setLogin(boolean login) {
        this.login = login;
    }

    public String getrYear() {
        return rYear;
    }

    public void setrYear(String rYear) {
        this.rYear = rYear;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getDoi() {
        return doi;
    }

    public void setDoi(String doi) {
        this.doi = doi;
    }

    public String getIsbn10() {
        return isbn10;
    }

    public void setIsbn10(String isbn10) {
        this.isbn10 = isbn10;
    }

    public String getIsbn13() {
        return isbn13;
    }

    public void setIsbn13(String isbn13) {
        this.isbn13 = isbn13;
    }

    public String getEisbn13() {
        return eisbn13;
    }

    public void setEisbn13(String eisbn13) {
        this.eisbn13 = eisbn13;
    }

    public Set<String> getAuthors() {
        return authors;
    }

    public void setAuthors(Set<String> authors) {
        this.authors = authors;
    }

    public Set<String> getTranslators() {
        return translators;
    }

    public void setTranslators(Set<String> translators) {
        this.translators = translators;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getVolume() {
        return volume;
    }

    public void setVolume(String volume) {
        this.volume = volume;
    }

    public String getIssue() {
        return issue;
    }

    public void setIssue(String issue) {
        this.issue = issue;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public String getOther() {
        return other;
    }

    public void setOther(String other) {
        this.other = other;
    }

    public String getLanguage() {
        return language;
    }

    public void setLanguage(String language) {
        this.language = language;
    }

    public String getSubject() {
        return subject;
    }

    public void setSubject(String subject) {
        this.subject = subject;
    }

    public String getTxt1() {
        return txt1;
    }

    public void setTxt1(String txt1) {
        this.txt1 = txt1;
    }

    public String getAname() {
        return aname;
    }

    public void setAname(String aname) {
        this.aname = aname;
    }

    public String getAsname() {
        return asname;
    }

    public void setAsname(String asname) {
        this.asname = asname;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getYear() {
        return rYear;
    }

    public void setYear(String year) {
        this.rYear = year;
    }

    public String getEdition() {
        return edition;
    }

    public void setEdition(String edition) {
        this.edition = edition;
    }

    public boolean isLogin2() {
        return login2;
    }

    public void setLogin2(boolean login2) {
        this.login2 = login2;
    }

    public String getPname() {
        return pname;
    }

    public void setPname(String pname) {
        this.pname = pname;
    }

    public String getPcountry() {
        return pcountry;
    }

    public void setPcountry(String pcountry) {
        this.pcountry = pcountry;
    }

    public int getNumber1() {
        return number1;
    }

    public void setNumber1(int number1) {
        this.number1 = number1;
    }

    /*public Set<Author> getAuthorslist() {
     return authorslist;
     }

     public void setAuthorslist(Set<Author> authorslist) {
     this.authorslist = authorslist;
     }*/

    /* public Set<Author> getAt() {
     return translatorlist;
     }

     public void setAt(Set<Author> at) {
     this.translatorlist = at;
     }*/
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getNumberAuthor() {
        return numberAuthor;
    }

    public void setNumberAuthor(int numberAuthor) {
        this.numberAuthor = numberAuthor;
    }

    public String getError() {
        return error;
    }

    public void setError(String error) {
        this.error = error;
    }

    public Author getSelectedAuthor() {
        return selectedAuthor;
    }

    public void setSelectedAuthor(Author selectedAuthor) {
        try {
            if (selectedAuthor != null) {
                this.selectedAuthor = selectedAuthor;

                String[] ccc = selectedAuthor.getNames();
                aname1 = ccc[0];
                aname2 = ccc[1];
                aname3 = ccc[2];
                aname4 = ccc[3];
                aname5 = ccc[4];



            }
        } catch (Exception e) {
        }
    }

    public Reference getSelectedReference() {
        return selectedReference;
    }

    public void setSelectedReference(Reference selectedReference) {
        this.selectedReference = selectedReference;
    }

    public String getCurrentpassword() {
        return currentpassword;
    }

    public void setCurrentpassword(String Currentpassword) {
        this.currentpassword = Currentpassword;
    }

    public String getAname1() {
        return aname1;
    }

    public void setAname1(String Aname1) {
        this.aname1 = Aname1;
    }

    public String getAname2() {
        return aname2;
    }

    public void setAname2(String Aname2) {
        this.aname2 = Aname2;
    }

    public String getAname3() {
        return aname3;
    }

    public void setAname3(String Aname3) {
        this.aname3 = Aname3;
    }

    public String getAname4() {
        return aname4;
    }

    public void setAname4(String Aname4) {
        this.aname4 = Aname4;
    }

    public String getAname5() {
        return aname5;
    }

    public void setAname5(String Aname5) {
        this.aname5 = Aname5;
    }

    /*public Set<Author> getTranslatorlist() {
     return translatorlist;
     }

     public void setTranslatorlist(Set<Author> translatorlist) {
     this.translatorlist = translatorlist;
     }

     public int getCountAuthorlistSize() {
     return authorslist.size();
     }*/

    /*public void setCountAuthorlistSize(int countAuthorlistSize) {
     this.countAuthorlistSize = countAuthorlistSize;
     }*/

    /*public int getCountTranslatorlistSize() {
     return translatorlist.size();
     }*/

    /*public void setCountTranslatorlistSize(int countTranslatorlistSize) {
     this.countTranslatorlistSize = countTranslatorlistSize;
     }*/
    public Translator getSelectedTranslator() {
        return selectedTranslator;
    }

    public void setSelectedTranslator(Translator selectedTranslator) {
        this.selectedTranslator = selectedTranslator;
    }

    public AcademicSet getSelectedAcademicSet() {
        return selectedAcademicSet;
    }

    public void setSelectedAcademicSet(AcademicSet selectedAcademicSet) {
        /*if (selectedAcademicSet != null)
         selectedAcademicSetName = selectedAcademicSet.getName(); */
        this.selectedAcademicSet = selectedAcademicSet;
    }

    public UIData getDataTableForViewSets() {
        return dataTableForViewSets;
    }

    public void setDataTableForViewSets(UIData dataTableForViewSets) {
        this.dataTableForViewSets = dataTableForViewSets;
    }

    public String getSelectedAcademicSetName() {
        /*try {
         selectedAcademicSetName = selectedAcademicSet.getName();
         } catch (Exception e) {
         } */
        return selectedAcademicSetName;
    }

    public void setSelectedAcademicSetName(String selectedAcademicSetName) {
        this.selectedAcademicSetName = selectedAcademicSetName;
    }

    public Reference getSelectedSetReference() {
        return selectedSetReference;
    }

    public void setSelectedSetReference(Reference selectedSetReference) {
        this.selectedSetReference = selectedSetReference;
    }

    public Reference getSelectedReferenceInsideSet() {
        return selectedReferenceFromAll;
    }

    public void setSelectedReferenceInsideSet(Reference selectedReferenceInsideSet) {
        this.selectedReferenceFromAll = selectedReferenceInsideSet;
    }
    ///////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////// create
    //@EJB
//private AccessInterfaceLocal Userservice;
//private String name; 
//private String email; 
    private String rights = "user";
//private String password;
    private String currenterror = "";

//private Author selectedAuthor;
    /*public String getPassword() {
     return password;
     }

     public void setPassword(String password) {
     this.password = password;
     }*/
    public String createUser() {
        // User newUser = new User(name,email,rights);
        // Userservice.addUser(newUser);
        //return "home?faces-redirect=true";
        //http://crackstation.net/hashing-security.htm
        AccUser newGPU = new AccUser(name, email, rights, password);//md5 not good enough
        if (Userservice.UserExist(0, newGPU.getEmail())) {
            currenterror = "Nooooooooooooooooooooo";
            return "error?faces-redirect=true&er=nonnnnnn";
        } else {       //String newname = String(newGPU.getName().charAt(0));
            newGPU.setName(Character.toUpperCase(newGPU.getName().charAt(0)) + newGPU.getName().substring(1));
            Userservice.addUser(newGPU);
            //return "home?faces-redirect=true"; take user to login page
            return "login?faces-redirect=true";
        }
    }

    /*public String getName() {
     return name;
     }

     public void setName(String name) {
     this.name = name;
     }

     public String getEmail() {
     return email;
     }

     public void setEmail(String email) {
     this.email = email;
     }*/
    public String getRights() {
        return rights;
    }

    public void setRights(String rights) {
        this.rights = rights;
    }

    /**
     * Creates a new instance of Create
     */
    public boolean isRenderEdition() {
        return renderEdition;
    }

    public void setRenderEdition(boolean renderEdition) {
        this.renderEdition = renderEdition;
    }

    public boolean isRenderCity() {
        return renderCity;
    }

    public void setRenderCity(boolean renderCity) {
        this.renderCity = renderCity;
    }

    public boolean isRenderDoi() {
        return renderDoi;
    }

    public void setRenderDoi(boolean renderDoi) {
        this.renderDoi = renderDoi;
    }

    public boolean isRenderIsbn() {
        return renderIsbn;
    }

    public void setRenderIsbn(boolean renderIsbn) {
        this.renderIsbn = renderIsbn;
    }

    public boolean isRenderPages() {
        return renderPages;
    }

    public void setRenderPages(boolean renderPages) {
        this.renderPages = renderPages;
    }

    public boolean isRenderVolume() {
        return renderVolume;
    }

    public void setRenderVolume(boolean renderVolume) {
        this.renderVolume = renderVolume;
    }

    public boolean isRenderIssue() {
        return renderIssue;
    }

    public void setRenderIssue(boolean renderIssue) {
        this.renderIssue = renderIssue;
    }

    public boolean isRenderUrl() {
        return renderUrl;
    }

    public void setRenderUrl(boolean renderUrl) {
        this.renderUrl = renderUrl;
    }

    public boolean isRenderDate() {
        return renderDate;
    }

    public void setRenderDate(boolean renderDate) {
        this.renderDate = renderDate;
    }

    public Map<String, String> getLanguages() {
        return languages;
    }

    public void setLanguages(Map<String, String> languages) {
        this.languages = languages;
    }

    public Date getDate2() {
        return date2;
    }

    public void setDate2(Date date2) {
        this.date2 = date2;
    }

    public boolean isRenderOnRowSelect() {
        return renderOnRowSelect;
    }

    public void setRenderOnRowSelect(boolean renderOnRowSelect) {
        this.renderOnRowSelect = renderOnRowSelect;
    }

    public boolean isRenderOnRowSelectREF() {
        return renderOnRowSelectREF;
    }

    public void setRenderOnRowSelectREF(boolean renderOnRowSelectREF) {
        this.renderOnRowSelectREF = renderOnRowSelectREF;
    }

    public boolean isRenderOnRowSelectSET() {
        return renderOnRowSelectSET;
    }

    public void setRenderOnRowSelectSET(boolean renderOnRowSelectSET) {
        this.renderOnRowSelectSET = renderOnRowSelectSET;
    }

    public UIData getDataTable() {
        return dataTable;
    }

    public void setDataTable(UIData dataTable) {
        this.dataTable = dataTable;
    }

    public UIData getDataTable2() {
        return dataTable2;
    }

    public void setDataTable2(UIData dataTable2) {
        this.dataTable2 = dataTable2;
    }

    public UIData getDataTable3() {
        return dataTable3;
    }

    public void setDataTable3(UIData dataTable3) {
        this.dataTable3 = dataTable3;
    }

    public UIData getDataTable4() {
        return dataTable4;
    }

    public void setDataTable4(UIData dataTable4) {
        this.dataTable4 = dataTable4;
    }

    public UIData getDataTable5() {
        return dataTable5;
    }

    public void setDataTable5(UIData dataTable5) {
        this.dataTable5 = dataTable5;
    }

    public UIData getDataTable6() {
        return dataTable6;
    }

    public void setDataTable6(UIData dataTable6) {
        this.dataTable6 = dataTable6;
    }

    public int getOldPubID() {
        return oldPubID;
    }

    public void setOldPubID(int oldPubID) {
        this.oldPubID = oldPubID;
    }

    public Reference getSelectedReferenceFromAll() {
        return selectedReferenceFromAll;
    }

    public void setSelectedReferenceFromAll(Reference selectedReferenceFromAll) {
        this.selectedReferenceFromAll = selectedReferenceFromAll;
    }

    public Format getSelectedFormat() {
        return selectedFormat;
    }

    public void setSelectedFormat(Format selectedFormat) {
        this.selectedFormat = selectedFormat;
    }

    public boolean isHasPub() {
        return hasPub;
    }

    public void setHasPub(boolean hasPub) {
        this.hasPub = hasPub;
    }

    /*public List<AcademicSet> getAllFormats() {
     return allFormats;
     }

     public void setAllFormats(List<AcademicSet> allFormats) {
     this.allFormats = allFormats;
     }*/
    public String getCurrenterror() {
        return currenterror;
    }

    public void setCurrenterror(String currenterror) {
        this.currenterror = currenterror;
    }

    public boolean isRenderOnRowSelectFOR() {
        return renderOnRowSelectFOR;
    }

    public void setRenderOnRowSelectFOR(boolean renderOnRowSelectFOR) {
        this.renderOnRowSelectFOR = renderOnRowSelectFOR;
    }

    public boolean isRenderOnRowSelectFORDETAIL() {
        return renderOnRowSelectFORDETAIL;
    }

    public void setRenderOnRowSelectFORDETAIL(boolean renderOnRowSelectFORDETAIL) {
        this.renderOnRowSelectFORDETAIL = renderOnRowSelectFORDETAIL;
    }

    /*public List<Format> getAllFormats() {
     return allFormats;
     }
     public void setAllFormats(List<Format> allFormats) {
     this.allFormats = allFormats;
     }*/
    public Format getCurrentFormat() {
        return currentFormat;
    }

    public void setCurrentFormat(Format currentFormat) {
        this.currentFormat = currentFormat;
    }

    /*public List<String> getElementsSmall() {
     return elementsSmall;
     }
     public void setElementsSmall(List<String> elementsSmall) {
     this.elementsSmall = elementsSmall;
     }*/

    /*public List<String> getDroppedCars() {
     return droppedCars;
     }
     public void setDroppedCars(List<String> droppedCars) {
     this.droppedCars = droppedCars;
     }*/
    public String getRefExample() {
        return refExample;
    }

    public void setRefExample(String refExample) {
        this.refExample = refExample;
    }

    public Element getSelectedCar() {
        return selectedCar;
    }

    public void setSelectedCar(Element selectedCar) {
        this.selectedCar = selectedCar;
    }
}
